package com.example.mychat.Utils;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.concurrent.ConcurrentHashMap;

@Component
public class UserSessionRegistry {
    private ConcurrentHashMap<String, WebSocketSession> userSessions=new ConcurrentHashMap<>();
    /**
     *存储session对象
     * @param userId 用户唯一id
     * @param sessionId 用户对应的session对象
     */
    public void registerSession(String userId,WebSocketSession sessionId){
        userSessions.put(userId,sessionId);
    }
    public WebSocketSession getSessionId(String userId){
        return userSessions.get(userId);
    }

}
